package com.sl.plugin.step.workflow;

import com.sl.core.engine.meta.impl.AbstractProcessCompDescriptor;
import com.sl.core.engine.step.ProcessCompService;
import com.sl.core.engine.step.impl.AbstractProcessComp;
import com.sl.plugin.step.childflow.ChildFlowComp;
import com.sl.plugin.step.childflow.ChildFlowCompContext;
import com.sl.plugin.step.childflow.ChildFlowCompDescriptor;

import java.util.Map;

/**
 *
 */
public class WorkflowUserTaskComp extends AbstractProcessComp<Map<String, Object>, Object> implements ProcessCompService {

    private ChildFlowComp childFlowComp;

    public WorkflowUserTaskComp(WorkflowUserTaskCompDescriptor abstractProcessCompDescriptor) {
        super(abstractProcessCompDescriptor);
        AbstractProcessCompDescriptor.CompConstructor constructor = abstractProcessCompDescriptor.getCompConstructor();
        ChildFlowCompDescriptor childFlowCompDescriptor = new ChildFlowCompDescriptor();
        AbstractProcessCompDescriptor.CompConstructor compConstructor = new AbstractProcessCompDescriptor.CompConstructor(
                constructor.getStepMeta(), new ChildFlowCompDescriptor(), new ChildFlowCompContext(), 0, constructor.getTransMeta(), constructor.getTrans()
        );

        childFlowCompDescriptor.setCompConstructor(compConstructor);
        childFlowComp = new ChildFlowComp(childFlowCompDescriptor);
    }


    @Override
    public Object input(Map<String, Object> map) {
        return childFlowComp.input(map);
    }

    @Override
    protected Boolean isBreak(Boolean compensateFlag) {
        //判断本次运行中是否 存在某些关键变量，如果不存在证明是不能自动执行，直接break了
        if (!compensateFlag) {
            return true;
        }
        return false;
    }

}
